package com.weimob.mcloud.wechatwork.customer.third;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.weimob.mcloud.wechatwork.customer.service.user.enums.UrlConverTypeEnum;
import com.weimob.shorturl.model.UrlErrorVo;
import com.weimob.shorturl.model.request.CreateShortUrlRequest;
import com.weimob.shorturl.model.response.ShortUrlOut;
import com.weimob.shorturl.service.WeimobUrlConverService;
import com.weimob.soa.common.response.SoaResponse;
import com.weimob.soa.common.utils.SoaUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 链接转换接口客户端
 *
 * @Author LeoLee
 * @Date 2022/6/23 14:10
 * @Version 1.0
 */
@Component
@Slf4j
public class UrlConverProxy {

    @Reference
    private WeimobUrlConverService weimobUrlConverService;

    public ShortUrlOut createShortUrl(UrlConverTypeEnum urlConverTypeEnum, String url, String shortUrlPrefix) {
        CreateShortUrlRequest createShortUrlRequest = new CreateShortUrlRequest();
        createShortUrlRequest.setLongUrl(url);
        createShortUrlRequest.setUrlType(urlConverTypeEnum.getType());
        createShortUrlRequest.setShortUrlPrefix(shortUrlPrefix);
        log.info("com.weimob.mcloud.wechatwork.customer.third.UrlConverProxy.createShortUrl params:{}", JSON.toJSONString(createShortUrlRequest));
        SoaResponse<ShortUrlOut, UrlErrorVo> shortUrl = weimobUrlConverService.createShortUrl(createShortUrlRequest);
        log.info("com.weimob.mcloud.wechatwork.customer.third.UrlConverProxy.createShortUrl response:{}", JSON.toJSONString(shortUrl));
        return SoaUtil.unpack(shortUrl);
    }
}
